import { Observer } from "mobx-vue"
import { Component, Vue } from "vue-property-decorator";
// import {activityAdd} from 'src/utils/axios'
import CsjUpload from 'src/views/components/upload/upload.vue'
import { imagesOssPrefix } from "src/utils/ztbase";
@Observer
@Component({
  props: {
    clear: {
      type: Boolean,
      default: false
    }
  },
  components: {
    CsjUpload
  }
})
export default class ActivityAdd extends Vue {
  dateOptions: any = {};
  isShowModel: boolean = false;
  loading: boolean = false;
  //防暴力点击
  isCreateBtn: boolean = true;
  // form
  formItem: any = {
    name: '', //活动名称
    fs_color: '',//活动规则字体颜色
    rule_image: '', //规则图
    expire_begin_time: '', //活动有效起始时间
    expire_end_time: '',//活动有效结束时间
    expire_font_color: '', //倒计时文字颜色
    expire_background_color: '',//倒计时时间背景色
    background_image: '',//活动主页大背景图
    background_color: '',//活动主页背景色  
    //分享  
    share_title: '', //分享标题   
    share_text: '', //分享内容
    share_pic: '',//分享小图
    share_success_button_image: '', //分享：成功按钮图片，eg.:`我明白了`
    //其他
    h5_preview_link: '', //分享链接
    // help_button_area_image:'', //头像区域背景图(暂时不要)
    help_complete_text_left_right_pic: '',//左右修饰图
    activity_rule_index_image: '',//活动首页：规则引导按钮图
    activity_help_index_image: '',//活动首页：助力引导按钮图
    share_background_image: '',//助力模块：恭喜达成背景图
    help_success_image: '',//助力成功按钮图
    download_app_image: '',  //app下载图片
    goods_exchange_over: '',//商品兑换完图片
    //商品
    product_background_image: '',//商品背景图片
    product_image_background_image: '',//助力：产品区域背景色

    product_share_button_image: '',//助力邀请按钮图
    // help_under_price_pic:'',//助力标签图，eg：'神助力价'
    //助力页面：我的助力
    help_title: '', //标题
    // help_background_image: '', //页面背景图(暂时不要)
    help_background_color: '',//页面背景颜色
    help_photo_background_image: '', //头像模块背景颜色
    help_button_background_image: '',//助力成功弹窗图
    help_button_image: '',//按钮模块图片  
    help_button_text: '', //助力：拼接发起人的文字描述，eg.:小柚子的后援团
    //助力页面：他的助力 
    help_others_title: '', //标题
    // help_others_background_image: '', //页面背景图(暂时不要)
    help_others_background_color: '',//页面背景颜色
    help_others_photo_background_image: '', //头像背景颜色
    help_others_button_background_image: '',//按钮模块背景图
    help_others_button_text: '',//
    // 优惠卷添加数组
    coupon_image_url: []
  }

  mounted() {
    let vm: any = this;
    vm.isShowModel = true;
  }
  //关闭
  close() {
    let vm: any = this;
    let xwindow: any = window
    vm.isShowModel = false;
    if (!vm.clear) {
      xwindow.clearBodyStyle()
    }
    vm.$emit('close')
  }
  //确定
  async confirm() {
    let vm: any = this;
    let xwindow: any = window;
    //验证
    if (!vm.formItem.name) {
      vm.$Message.error('请输入活动名称')
      return
    }
    if (!vm.isCreateBtn) {
      return
    }
    vm.isCreateBtn = false;
    let params: any = {
      name: vm.formItem.name, //活动名称
      rule_image: vm.formItem.rule_image, //规则图
      expire_begin_time: vm.formItem.expire_begin_time, //活动有效起始时间
      expire_end_time: vm.formItem.expire_end_time,//活动有效结束时间
      expire_font_color: vm.formItem.expire_font_color, //倒计时背景色
      expire_background_color: vm.formItem.expire_background_color,//倒计时间背景色
      background_image: vm.formItem.background_image,//活动主页大背景图
      background_color: vm.formItem.background_color,//活动主页背景色  
      //分享
      share_title: vm.formItem.share_title, //分享标题   
      share_text: vm.formItem.share_text, //分享内容
      share_pic: vm.formItem.share_pic,//分享小图
      share_success_button_image: vm.formItem.share_success_button_image, //分享：成功按钮图片，eg.:`我明白了`
      //其他
      h5_preview_link: vm.formItem.h5_preview_link, //分享链接
      // help_button_area_image:vm.formItem.help_button_area_image, //头像区域背景图(暂时不要)
      help_complete_text_left_right_pic: vm.formItem.help_complete_text_left_right_pic,//左右修饰图
      activity_rule_index_image: vm.formItem.activity_rule_index_image,//活动首页：规则引导按钮图
      activity_help_index_image: vm.formItem.activity_help_index_image, //活动首页：助力引导按钮图
      share_background_image: vm.formItem.share_background_image,//助力模块：恭喜达成背景图
      help_success_image: vm.formItem.help_success_image,//助力成功按钮图
      download_app_image: vm.formItem.download_app_image,  //app下载图片
      goods_exchange_over: vm.formItem.goods_exchange_over,//商品兑换完图片
      //商品
      product_background_image: vm.formItem.product_background_image,//商品背景图片
      product_image_background_image: vm.formItem.product_image_background_image,//助力：产品区域背景色

      product_share_button_image: vm.formItem.product_share_button_image,//助力邀请按钮图
      // help_under_price_pic:vm.formItem.help_under_price_pic,//助力标签图，eg：'神助力价'
      //助力页面：我的助力
      help_title: vm.formItem.help_title, //标题
      // help_background_image: vm.formItem.help_background_image, //页面背景图(暂时不要)
      help_background_color: vm.formItem.help_background_color,//页面背景颜色
      help_photo_background_image: vm.formItem.help_photo_background_image, //头像背景色
      help_button_background_image: vm.formItem.help_button_background_image,//助力成功弹窗
      help_button_image: vm.formItem.help_button_image,//按钮模块图片  
      help_button_text: vm.formItem.help_button_text, //发起人描述
      //助力页面：他的助力 
      help_others_title: vm.formItem.help_others_title, //标题
      // help_others_background_image: vm.formItem.help_others_background_image, //页面背景图(暂时不要)
      help_others_background_color: vm.formItem.help_others_background_color,//页面背景颜色
      help_others_photo_background_image: vm.formItem.help_others_photo_background_image, //头像背景色
      help_others_button_background_image: vm.formItem.help_others_button_background_image,//按钮模块背景图
      // help_others_button_text:vm.formItem.help_others_button_text,//按钮模块文字
    }
    // 获取数据
    // let out: any = await activityAdd(params)
    // if (out.success) {
    //     vm.isShowModel = false;
    //     if (!vm.clear) {
    //         xwindow.clearBodyStyle()
    //     }
    //     vm.$emit('confirm')
    // } else {
    //     vm.$Message.error(out.error.msg)
    // }
    vm.isCreateBtn = true;
  }
  // 图片补全前缀
  imagePrefix(url, zoomScale) {
    return imagesOssPrefix(url, zoomScale)
  }
  //转化时间
  changeTime(val) {
    let xwindow: any = window
    return xwindow.conversionTime.timeToYMdHms(val)
  }

  // 优惠卷模块

  // 数组元素交换位置
  swapArray(arr, index1, index2) {
    arr[index1] = arr.splice(index2, 1, arr[index1])[0];
    return arr;
  }

  //增加
  add(type) {
    let vm: any = this;
    switch (type) {
      case 'dsp':
        vm.formItem.big_product_image_url.push({ goods_id: '', link_url: '' });
        break;
      case 'xsp':
        vm.formItem.little_product_image_url.push({ goods_id: '', link_url: '' });
        break;
      case 'yhq':
        vm.formItem.coupon_image_url.push({ coupon_url: '', coupon_image: '' });
        break;
    }
  }
  //删除
  del(index, type) {
    let vm: any = this;
    switch (type) {
      case 'dsp':
        vm.formItem.big_product_image_url.splice(index, 1);
        break;
      case 'xsp':
        vm.formItem.little_product_image_url.splice(index, 1);
        break;
      case 'yhq':
        vm.formItem.coupon_image_url.splice(index, 1);
        break;
    }
  }
  //向下移动
  down(index, type) {
    let vm: any = this;
    switch (type) {
      case 'dsp':
        vm.swapArray(vm.formItem.big_product_image_url, index, index + 1);
        break;
      case 'xsp':
        vm.swapArray(vm.formItem.little_product_image_url, index, index + 1)
        break;
      case 'yhq':
        vm.swapArray(vm.formItem.coupon_image_url, index, index + 1);
        break;
    }
  }
  //向上移动
  up(index, type) {
    let vm: any = this;
    switch (type) {
      case 'dsp':
        vm.swapArray(vm.formItem.big_product_image_url, index, index - 1);
        break;
      case 'xsp':
        vm.swapArray(vm.formItem.little_product_image_url, index, index - 1);
        break;
      case 'yhq':
        vm.swapArray(vm.formItem.coupon_image_url, index, index - 1);
        break;
    }
  }
}